var path = require("path")
var fs = require("fs")
var mime = require("mime")

function readStaticFile(res, file_path){
    var ext = path.parse(file_path).ext
    var mime_type = mime.getType(ext)
    if(ext){
        fs.readFile(file_path, function(err, data){
            if(err){
                res.writeHead(404,{"Content-Type": "text/plain" })
                res.write("404-File not found!!!")
                res.end()
            }else{
                res.writeHead(200,{"Content-Type":mime_type})
                res.write(data)
                res.end()
            }
        })

        return true
    }else{
        res.writeHead(404,{"Content-Type": "text/plain" })
        res.write("404-url invalid!!!")
        res.end()
        return false
    }

}

module.exports.readStaticFile = readStaticFile